package lime49.lockcrypt.mobile;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import java.io.*;

public class PWBox implements CommandListener {
    private Form form;
    private TextField pwField;
    private String pass = null;
    private Display display;
    private LockCrypt midlet;
    
    public PWBox(LockCrypt midlet) { //Display disp) {
        this.midlet = midlet;
        this.display = midlet.getDisplay();
        form = new Form("Enter Password");
        form.addCommand(new Command("Ok", Command.OK, 1));
        form.addCommand(new Command("Exit", Command.EXIT, 1));
        form.setCommandListener(this);
        pwField = new TextField("Password:", "", 25, TextField.PASSWORD);
            form.append(pwField);
    }
    public void setCurrent() {
        display.setCurrent(form);
    }
    public String getPassword() {
        return pass;
    }
    public void wrongPass() {
         Alert error = new Alert("Incorrect Password", "Please try again", null, AlertType.ERROR);
         error.setTimeout(Alert.FOREVER);
         pwField.setString("");
         pass = null;
         display.setCurrent(error, form);
    }
    /* CommandListener */
    public void commandAction(Command command, Displayable disp) {
        int comm = command.getCommandType();
        if(comm == Command.OK) {
            pass = pwField.getString();
        } else if(comm == Command.EXIT) {
            midlet.destroyApp(true);
        }
    }
    
    
}
